import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:yt_devops/components/gaps.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/components/yt_text_style.dart';
import 'package:yt_devops/pages/site/widgets/statistics_itme_widget.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';

/**
 *
 * @Description TODO
 * @Author liuer
 * @CreateTime 2024年03月22日 14:02
 */
class SiteOverviewWidget extends StatelessWidget {
  final String energyOptions;
   String monetaryUnitName;
  final Map<String,dynamic> energyData;
   SiteOverviewWidget({Key? key,required this.energyOptions,required this.energyData,required this.monetaryUnitName,}) : super(key: key);
  List <String> titleList = [
    ResKey.totalRevenue.tr,
    'device.pvRevenue'.tr,
    'device.storageRevenue'.tr,
    'device.chargingRevenue'.tr,
    'device.selfUseRate'.tr,
    'device.loadSelfRate'.tr,
    'device.storageCharge'.tr,
    'device.storageDischarge'.tr
  ];
  /// 1 今日光伏自发电量 光伏发电	2储能充电量 储能放电量  3充电桩充电量 	4负载用电量  	5市电电量
  @override
  Widget build(BuildContext context) {
    GetStorage storage = GetStorage();
    monetaryUnitName = storage.read('monetaryUnitName')??'元';
    if(monetaryUnitName == '元' || monetaryUnitName == '¥'){
      monetaryUnitName = ResKey.yuan.tr;
    }
    Log.d('energyData==' + energyData.toString());
    return Container(
      margin: EdgeInsets.only(left: 16.w,right: 16.w),
      padding: EdgeInsets.only(left: 16.w,top: 16.w),
      decoration: const BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(8))),
      // color: Colors.white,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Gaps.vGap10,
          Text(ResKey.dataBoard.tr,style: ytTextStyle(fontSize: 16,color: Colour.black2dTextColor,fontWeight: FontWeight.w500),),
          Gaps.vGap12,
          _typeWidgets(),
          Gaps.vGap16
        ],
      ),
    );
  }
  // 1光伏站点 2儲能站点  、3充电站点，   光储站点，"12"，（”光储充站点”，"123"），（儲沖中站点，23) 光充站点13
  _typeWidgets(){
    Widget returnWidget = Container();
    if(energyOptions == '123'){
        returnWidget = Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Row(
              children: [
                StatisticsItemWidget(titleList[0], energyData['totalGains'] != null?energyData['totalGains'].toString():'--',
                    ResKey.yuan.tr,monetaryUnitName),
                Gaps.hGap10,
                StatisticsItemWidget(titleList[1], energyData['photovoltaicGains'] != null?energyData['photovoltaicGains'].toString():'--', ResKey.yuan.tr,monetaryUnitName),
              ],
            ),
            Gaps.vGap10,
            Row(
              children: [
                StatisticsItemWidget(titleList[2],energyData['essGains'] != null?energyData['essGains'].toString():'--', ResKey.yuan.tr,monetaryUnitName),
                Gaps.hGap10,
                StatisticsItemWidget(titleList[3], energyData['chargingPileGains'] != null?energyData['chargingPileGains'].toString():'--' ,ResKey.yuan.tr,monetaryUnitName),
              ],
            ),
            Gaps.vGap10,
            Row(
              children: [
                StatisticsItemWidget(titleList[4], energyData['selfUseRate'] != null?energyData['selfUseRate'].toString():'--', '%',monetaryUnitName),
                Gaps.hGap10,
                StatisticsItemWidget(titleList[5], energyData['selfSufficiencyRate'] != null?energyData['selfSufficiencyRate'].toString():'--', '%',monetaryUnitName),
              ],
            ),
          ],
        );
    }else if(energyOptions == '12'){
      returnWidget = Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Row(
            children: [
              StatisticsItemWidget(titleList[0], energyData['totalGains'] != null?energyData['totalGains'].toString():'--', ResKey.yuan.tr,monetaryUnitName),
              Gaps.hGap10,
              StatisticsItemWidget(titleList[1], energyData['photovoltaicGains'] != null?energyData['photovoltaicGains'].toString():'--', ResKey.yuan.tr,monetaryUnitName),
            ],
          ),
          Gaps.vGap10,
          Row(
            children: [
              StatisticsItemWidget(titleList[2],energyData['essGains'] != null?energyData['essGains'].toString():'--', ResKey.yuan.tr,monetaryUnitName),
              Gaps.hGap10,
              StatisticsItemWidget(titleList[4], energyData['selfUseRate'] != null?energyData['selfUseRate'].toString():'--', '%',monetaryUnitName),
            ],
          ),
          Gaps.vGap10,
          Row(
            children: [
              StatisticsItemWidget(titleList[5], energyData['selfSufficiencyRate'] != null?energyData['selfSufficiencyRate'].toString():'--', '%',monetaryUnitName),
              Gaps.hGap10,
              SizedBox(
                height: 70,
                width: (ScreenUtil().screenWidth - 42.w ) / 2,
              )
            ],
          ),
        ],
      );
    }else if(energyOptions == '13'){
      returnWidget = Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Row(
            children: [
              StatisticsItemWidget(titleList[0], energyData['totalGains'] != null?energyData['totalGains'].toString():'--', ResKey.yuan.tr,monetaryUnitName),
              Gaps.hGap10,
              StatisticsItemWidget(titleList[1], energyData['photovoltaicGains'] != null?energyData['photovoltaicGains'].toString():'--', ResKey.yuan.tr,monetaryUnitName),
            ],
          ),
          Gaps.vGap10,
          Row(
            children: [
              StatisticsItemWidget(titleList[3], energyData['chargingPileGains'] != null?energyData['chargingPileGains'].toString():'--' ,ResKey.yuan.tr,monetaryUnitName),
              Gaps.hGap10,
              StatisticsItemWidget(titleList[4], energyData['selfUseRate'] != null?energyData['selfUseRate'].toString():'--', '%',monetaryUnitName),
            ],
          ),
          Gaps.vGap10,
          Row(
            children: [
              StatisticsItemWidget(titleList[5], energyData['selfSufficiencyRate'] != null?energyData['selfSufficiencyRate'].toString():'--', '%',monetaryUnitName),
              Gaps.hGap10,
              SizedBox(
                height: 70,
                width: (ScreenUtil().screenWidth - 42.w ) / 2,
              )
            ],
          ),
        ],
      );
    }else if(energyOptions == '23'){
      returnWidget = Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Row(
            children: [
              StatisticsItemWidget(titleList[0], energyData['totalGains'] != null?energyData['totalGains'].toString():'--', ResKey.yuan.tr,monetaryUnitName),
              Gaps.hGap10,
              StatisticsItemWidget(titleList[2],energyData['essGains'] != null?energyData['essGains'].toString():'--', ResKey.yuan.tr,monetaryUnitName),],
          ),
          Gaps.vGap10,
          Row(
            children: [
              StatisticsItemWidget(titleList[6],energyData['storageCharge'] != null?energyData['storageCharge'].toString():'--', ResKey.yuan.tr,monetaryUnitName),
              Gaps.hGap10,
              StatisticsItemWidget(titleList[7], energyData['storageDischarge'] != null?energyData['storageDischarge'].toString():'--' ,ResKey.yuan.tr,monetaryUnitName),
            ],
          ),
          Gaps.vGap10,
          Row(
            children: [
              StatisticsItemWidget(titleList[3], energyData['chargingPileGains'] != null?energyData['chargingPileGains'].toString():'--' ,ResKey.yuan.tr,monetaryUnitName),
              Gaps.hGap10,
              SizedBox(height: 70,width: (ScreenUtil().screenWidth - 42.w ) / 2)
            ],
          ),
        ],
      );
    }
    else if(energyOptions == '1'){
      returnWidget = Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Row(
            children: [
              StatisticsItemWidget(titleList[1], energyData['photovoltaicGains'] != null?energyData['photovoltaicGains'].toString():'--', ResKey.yuan.tr,monetaryUnitName),
              Gaps.hGap10,
              StatisticsItemWidget(titleList[4], energyData['selfUseRate'] != null?energyData['selfUseRate'].toString():'--', '%',monetaryUnitName),
            ],
          ),
          Gaps.vGap10,
          Row(
            children: [
              StatisticsItemWidget(titleList[5], energyData['selfSufficiencyRate'] != null?energyData['selfSufficiencyRate'].toString():'--', '%',monetaryUnitName),
              Gaps.hGap10,
              SizedBox(
                height: 70,
                width: (ScreenUtil().screenWidth - 42.w ) / 2,
              )
            ],
          ),
        ],
      );
    }
    else if(energyOptions == '2'){
      returnWidget = dataOverview(energyData);
      //     Column(
      //   crossAxisAlignment: CrossAxisAlignment.stretch,
      //   children: [
      //     Row(
      //       children: [
      //         StatisticsItemWidget(titleList[2],energyData['essGains'] != null?energyData['essGains'].toString():'--', ResKey.yuan.tr),
      //         Gaps.hGap10,
      //         StatisticsItemWidget('储能充电电费',energyData['storageCharge'] != null?energyData['storageCharge'].toString():'--', ResKey.yuan.tr),
      //       ],
      //     ),
      //     Gaps.vGap10,
      //     Row(
      //       children: [
      //         StatisticsItemWidget('储能放电收入', energyData['storageDischarge'] != null?energyData['storageDischarge'].toString():'--' ,ResKey.yuan.tr),
      //         Gaps.hGap10,
      //         SizedBox(height: 70,width: (ScreenUtil().screenWidth - 42.w ) / 2)
      //       ],
      //     ),
      //   ],
      // );
    }
    else if(energyOptions == '3'){
      returnWidget = Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Gaps.vGap10,
          Row(
            children: [
              StatisticsItemWidget(titleList[3], energyData['chargingPileGains'] != null?energyData['chargingPileGains'].toString():'--' ,ResKey.yuan.tr,monetaryUnitName),
              Gaps.hGap10,
              SizedBox(height: 70,width: (ScreenUtil().screenWidth - 42.w ) / 2)
            ],
          ),
        ],
      );
    }
    return returnWidget;
  }

  dataOverview(Map map) {
    return Container(
      // margin: EdgeInsets.only(left: 16.w, right: 16.w, top: 10),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Row(
            children: [
              StatisticsItemWidget(ResKey.siteSettingObserverStoreChargePower.tr,
                  energyData['storageChargeElec'] != null?energyData['storageChargeElec'].toString():'--', 'kWh',monetaryUnitName),
              Gaps.hGap10,
              StatisticsItemWidget(ResKey.siteSettingObserverStoreDischargePower.tr,
                  energyData['storageDischargeElec'] != null?energyData['storageDischargeElec'].toString():'--' , 'kWh',monetaryUnitName),
            ],
          ),
          Gaps.vGap10,
          Row(
            children: [
              StatisticsItemWidget(titleList[6], energyData['storageCharge'] != null?energyData['storageCharge'].toString():'--', ResKey.yuan.tr,monetaryUnitName),
              Gaps.hGap10,
              StatisticsItemWidget(titleList[7],energyData['storageDischarge'] != null?energyData['storageDischarge'].toString():'--' , ResKey.yuan.tr,monetaryUnitName),
            ],
          ),
          Gaps.vGap10,
          Container(
            // padding: EdgeInsets.only(left: 12.w,right: 12.w),
            margin: EdgeInsets.only(right: 16.w),
            height: 66,
            decoration: BoxDecoration(
                borderRadius:  BorderRadius.circular(10),
                color:Colour.backgroundF5F5F7Color
            ),
            alignment: Alignment.center,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,

              children: [
                Gaps.vGap14,
                Text.rich(
                  TextSpan(
                    children: [
                      TextSpan(text: energyData['totalGains'] != null?energyData['totalGains'].toString():'--', style: dinTextStyle(fontSize: 18,color: Colour.mainTextColor,fontWeight: FontWeight.w500),),
                      TextSpan(text: ResKey.yuan.tr, style: ytTextStyle(fontSize: 11,color: Colour.mainTextColor,)),
                    ],
                  ),
                ),
                Gaps.vGap2,
                Text(titleList[2],textAlign: TextAlign.center, style: ytTextStyle(fontSize: 12,color: Colour.labelTextColor, fontWeight: FontWeight.normal),),
              ],
            ),
          ),
          // Row(
          //   children: [
          //     StatisticsItemWidget(titleList[2],energyData['gain'] != null?energyData['gain'].toString():'--' , ResKey.yuan.tr),
          //     // Gaps.hGap10,
          //     // SizedBox(
          //     //   height: 70,
          //     //   width: (ScreenUtil().screenWidth - 42.w) / 2,
          //     // )
          //   ],
          // ),
        ],
      ),
    );
  }
}
